<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	function sendForm() {
		var hobbyChk = document.form1.hobby;//checkbox 배열
		var cnt = 0;
		for (var idx = 0; idx < hobbyChk.length; idx++) {
			if (hobbyChk[idx].checked) {//checkbox 객체. checked -> true(체크 됬으면) || false(체크 안 됬으면)
				cnt++;
			}
		}
		/*
		if(cnt==0) {
			alert("취미를 선택하세요");
		}else {
			document.form1.submit();
		}
		*/
		//라디오 체크 버튼
		var gender = document.form1.gender;//배열
		var cnt2 = 0;
		for(var i = 0; i<gender.length; i++) {
			//라디오버튼 체크여부 : 라디오객체.checked - true(체크) || false
			if(gender[i].checked) {
				cnt2++;
			}
		
		}
		if(cnt==0) {
			alert("취미를 선택하세요");
			return;
		}
		if(!cnt2) {//cnt2==0
			alert("성별을 선택하세요.");
		}else {
			document.form1.submit();
		}
	}
	

	function checkAll() {
		var hobbyChk = document.form1.hobby;
		var allChk = document.form1.allchk;
		var cnt = 0;
		if (!allChk.checked) {
			for (var idx = 0; idx < hobbyChk.length; idx++) {
				if(!hobbyChk[idx].checked) {
				hobbyChk[idx].click();
				}else {
					
				}
			}
		} else {
			for (var idx = 0; idx < hobbyChk.length; idx++) {
				if(hobbyChk[idx].checked) {
					hobbyChk[idx].click();
			}else	{
				
			}
			}

		}

	}
</script>
</head>
<body>
	<form name="form1" action="a.jsp">
		취미를 선택하세요<br> 
			<label> 당구 <input type="checkbox" name="hobby" value="dangu"></label> 
			<label> 영화 <input type="checkbox" name="hobby" value="movie"></label>
			<label>	노래 <input type="checkbox" name="hobby" value="sing"></label> 
			<label> 피아노 <input type="checkbox" name="hobby" value="piano"></label>
			<label> 게임 <input type="checkbox" name="hobby" value="game"></label>
			<br> 	
			<label>전체 체크 <input type="checkbox" name="allchk" onClick="checkAll();"></label> <br>
			<br>
			성별선택 <br>
			남 : <input type = "radio" name ="gender" value="male">
			여 : <input type = "radio" name ="gender" value="female">
			<input type="button" value="전송" onclick="sendForm();">
	</form>
</body>
</html>